package com.qiangou.ti.dome;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.junit.Test;

public class ToLogin {
	
	public static void main(String[] args) {
		
		
		
		
		
		
		
		
		
		
		
	}
	
	@Test
	public void testLogin() throws IOException {
		System.out.println("-------  请求来了  -------");
		
		// 请求地址
		String url = "https://login.ti.com/as/74Y7G/resume/as/authorization.ping" ;
		HttpClient client = new HttpClient();
		
		
		// post请求方式
		PostMethod postMethod = new PostMethod(url);
		// 推荐的数据存储方式,类似key-value形式
		NameValuePair telPair = new NameValuePair("pf.username", "1107176478@qq.com");
		NameValuePair pwdPair = new NameValuePair("pf.pass", "Chen4211296");
		NameValuePair adapterId = new NameValuePair("pf.adapterId", "IDPAdapterHTMLFormCIDStandard");
		// 封装请求参数
		postMethod.setRequestBody(new NameValuePair[] { telPair, pwdPair ,adapterId});
		// 这里是设置请求内容为json格式,根据站点的格式决定
		// 因为这个网站会将账号密码转为json格式,所以需要这一步
		postMethod.setRequestHeader("Content_Type", "application/json");
		
		postMethod.setRequestHeader("cookie", "ti_ua=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4662.6 Safari/537.36; CONSENTMGR=ts:1638344497467|consent:true; tiSessionID=017d74f1193d0001e1f4adef79f505071012506900bd0; _ga=GA1.2.987680230.1638344498; user_pref_language=\"zh-CN\"; pf-accept-language=zh-CN; _gcl_au=1.1.814293367.1638344549; _fbp=fb.1.1638344550452.809079995; ELOQUA=GUID=77E1475DBAF04CFF83056350419F5DF5; chipset=6917492; user_pref_shipTo=\"CN\"; user_pref_currency=\"CNY\"; ti_bm=; alias=homepageproduct; user_pref_givenName=\"\"; bm_sz=7512178063DC599A39F528928DD0DDAE~YAAQKto4fQnVWaJ9AQAAYYv9pw4MQjbeSlDxTZjxeGHwd9BFDnxfN/dOQSh1TSOD/mHaIG84zawRNkILZI+ugcl9wdDZCd1YB9CBxXURDceNQnnYhh3p+4zgKx7b7fxoPsrPfeGIc3oL44NckX9H6dcAZVrpIMjUZQUFT6JZvMy7TLlTGD/tHsTE7ycjNrhsXpTmIgVakGq6z+pHnCKX+K9tGQd/Q6g2i61R9XBiKK7PiyQxsVT66AqTZ9OQ3hFL4HFG0mmrRzyrMfEHoefU9KqWqed4me2TVtWb2bO1rA==~4534838~4474180; ti_geo=country=CN|city=GUANGZHOU|continent=AS|tc_ip=113.89.33.128; _gid=GA1.2.42645368.1639200960; bm_mi=DB25C079F03351889A206949A758A00A~UAMNSGNCCTkfVmEfnD0Oyn55IEhuJfOxuYHJSFkd4lOQMG+WyvhtVAleGWwjh4BZ0yogERUAogEP+1IlV+Xi0m8ga8kwk/sRaqtXd56zv4j4CC1ccotMgN/trdt1jcKXZDfD2aWXgAfZxXTtiBhqyjBQD7MrAT1k+sHVQgU3LTuhcUKHF/Id4CL2GF78clJtFdRpWl758KvTP4HxvpO6P2y88dPFwxFG1o02pU7ShRT0G8gtR2iCs5A9wLBXHiYQfZOY38+oShfjTtLEdqfEWi1v+i1AcNYWvSu33F4/0g8=; ak_bmsc=AC97E5B69983197FBBF887E618E95105~000000000000000000000000000000~YAAQrW2bG7QZjZ59AQAADZYBqA5woIwrFCfUC8drg/xjsV2gvZBGbpmmeINSX5sJgUOfDxWj8Y9fwfmktlQo/63D0gs/j0nvGI7Ckhhq63pBgZDTTrf9kin+5v4UcG6hWpfqQO3R6WDLwxsXXZGCa0ztx6MRiKmUVvMqlDQEMQamjZZnzCDt5ALqoq3ghhRsulBkj36eWVUcxBV+Z8VOPUIYE3tFHEuN/3k+N8Vfkaw7ca3bpsCfjCJXl5bK/tt0/N5mf3TLV4JKXz8AODDg/7wuUjUzdG/OcHfnr5BwsPo8RjByJK1nJE5eVGpeA83L+cWcHbG6RU3pQN6nAe4qx8Snhjonp0cdag+Lv4HXbWiS6r0bceJ5h6ZtKnEljMWOk4wp829+fkFyYIJlP1l/Eove5AD6uBQbJzc+qC4/C9Oz8DnzFTbw9lxq; ticontent=/auth; ga_content_cookie=/auth; login-check=true; ti_rid=718e344; PF=JURiCiVqceSFwDIGP1IJ62; bm_sv=E57E2C1BDF562EED4FD679C21670741D~CBokwTi1JoYn5X0UFMf0lMz7siIlPyOdh+LALnjy7d2puWONbA+TjT/wfIRyButykSJ+pUlWKc+ExCNkmocbDuiFhrlvab+yKj+ZEmMZCxnqRhtpsGonXyRETsG2SS5ygphf6T/jLh/O64k+J/sRNg==; tipage=/auth/as/authorization.oauth2-zh; tipageshort=as/authorization.oauth2-zh; ga_page_cookie=as/authorization.oauth2-zh; ABTasty=uid=jd5j5mps5b3cfd9n&fst=1638344498811&pst=1639046293366&cst=1639200960642&ns=6&pvt=25&pvis=7&th=684039.848371.2.2.1.1.1638762877134.1638762930606.1_789386.980946.8.4.2.1.1638753534496.1639201327873.1; ABTastySession=mrasn=&sen=11&lp=https%3A%2F%2Flogin.ti.com%2Fas%2Fauthorization.oauth2%3Fresponse_type%3Dcode%26scope%3Dopenid%20email%20profile%26client_id%3DDCIT_ALL_WWW-PROD%26state%3DnEqudiW6A-QFLGBWHtQNXtXXnkQ%26redirect_uri%3Dhttps%3A%2F%2Fwww.ti.com%2Foidc%2Fredirect_uri%2F%26nonce%3DpvpQk7mz4YRAIYwpYpHS-gIeJkAiLI_ZBMOwnzwRH2U%26response_mode%3Dform_post; da_sid=8FEE33EB8E32AE8911D2AA1349CFD1754C|4|0|3; da_lid=1D8F10B29A73EA12815BBB990B20DDA568|0|0|0; da_intState=; _abck=CDDEDC8400312F50D57F334132692BE8~-1~YAAQh6g8F7LD1519AQAAf50MqAc20qW/VIIi75d2UaJhpNd6ByfSG1IHx1CzlPFXFG2u0v0u5ui1y0jwPtX9HUJDpoakiMUxG2MtYM1Vn1zgaWHvbw3X6/twMIwxJ0cfZZR/3UlY47eQWz1m7OwZ4I8o31RlSeDnsy29krK+OyFhQFVaT1VZNDEgqUWFn08K8+LuTPKIv9w8ZcJZxTabCYEcRowtTW46e9yzBpKDYTzjZFisdPGO0cgYBANVGOtXeduU3L0VzPlDJHoZbQMXT6f2NGgpyMauliGPjxbQ9skxtwATbPqcLXzwy9DYK/L3R60KUp2W4fVuZb9r8pqr+LdAZMOpPOfbCXl18tcsJTbZZuH7bw7Tc/RwXkk+4gyVJy89DrvO8RgUsJPqGCkwlp4dZkHoH2G8ghXo05SDmyBUfZzA+OKoIbcTYLH7EpKynerdsr0=~-1~-1~-1; userType=Registered; _gat_ga_main_tracker=1; utag_main=v_id:017d74f1193d0001e1f4adef79f505071012506900bd0$_sn:8$_ss:0$_st:1639204026275$free_trial:false$dc_visit:8$channel:referral;exp-1641196913158$ctimestamp:Sat Dec 04 2021 16:01:53 GMT+0800 (中国标准时间);exp-1641196913158$_pn:8;exp-session$ses_id:1639200958570;exp-session$dc_event:10;exp-session$dc_region:ap-east-1;exp-session; _gali=loginbutton");
		System.out.println("执行请求");
		// 执行请求
		client.executeMethod(postMethod);
		System.out.println("执行请求w");
		// 通过Post/GetMethod对象获取响应头信息
		String cookie = postMethod.getResponseHeader("Set-Cookie").getValue();
		
		System.out.println("返回body: "+postMethod.getResponseBodyAsString());
		// 截取需要的内容
		System.out.println("cookie:"+ cookie);
		String sub = cookie.substring(cookie.indexOf("&"),
				cookie.lastIndexOf("&"));
		String[] splitPwd = sub.split("=");
		String pwd = splitPwd[1];
		System.out.println(pwd);
	}

}
